package br.com.estudosjsf.leilao.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.inject.Inject;

import br.com.estudosjsf.leilao.domain.Marca;
import br.com.estudosjsf.leilao.managedbean.ModeloBean;

@FacesConverter("marcaConverter")
public class MarcaConverter implements Converter {

	@Inject
	private ModeloBean modeloBean;
	
	@Override
	public Object getAsObject(FacesContext contexto, UIComponent componente, String marca) {
		Marca marcaObjeto = modeloBean.retornaMarcaPeloNome(marca);
		return (Marca) marcaObjeto;
	}

	@Override
	public String getAsString(FacesContext contexto, UIComponent componente, Object marcaObj) {
		return ((Marca)marcaObj).getNome();
	}
}
